package com.ken.forum.controller;

import com.ken.forum.common.AppResult;
import com.ken.forum.model.Board;
import com.ken.forum.services.IBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author Chooker
 */
@RestController
@Slf4j
@RequestMapping("/board")
@Api(tags = "板块接口")
public class BoardController {
    @Value("${forum.index.board-num: 9}")
    Integer num;

    @Resource
    private IBoardService boardService;

    @PostMapping("/topList")
    @ApiOperation("获取板块列表")
    public AppResult<List<Board>> topList() {
        List<Board> boards = boardService.selectByNum(num);
        return AppResult.success(boards);
    }

    @GetMapping("/getById")
    @ApiOperation("根据id获取板块信息")
    public AppResult<Board> getById(@ApiParam("板块id") @RequestParam("id") Long id) {
        Board board = boardService.selectById(id);
        return AppResult.success(board);
    }
}